package com.example.jack.community.view.me.personinfo;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.design.widget.TextInputLayout;
import android.support.percent.PercentRelativeLayout;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.jack.community.R;
import com.example.jack.community.model.me.Perfext_Per_infoView;
import com.example.jack.community.persenter.me.Perfext_Per_infoImp;
import com.example.jack.community.view.me.BlackStatusActivity;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import cn.pedant.SweetAlert.SweetAlertDialog;

/**
 * 完善个人信息
 */
public class Perfect_Per_infoActivity extends BlackStatusActivity implements Perfext_Per_infoView {

    @BindView(R.id.img_back)
    ImageView imgBack;
    @BindView(R.id.txt_back)
    TextView txtBack;
    @BindView(R.id.finish_text)
    TextView finishText;
    @BindView(R.id.edi_school)
    EditText ediSchool;
    @BindView(R.id.edi_name)
    EditText ediName;
    @BindView(R.id.edi_sex)
    EditText ediSex;
    @BindView(R.id.textInputLayout)
    TextInputLayout textInputLayout;
    @BindView(R.id.register_pass_setting_d)
    PercentRelativeLayout registerPassSettingD;
    @BindView(R.id.activity_res_pass)
    PercentRelativeLayout activityResPass;
    private Perfext_Per_infoImp perfext_per_infoImp = new Perfext_Per_infoImp();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.my_perfect__per_info);
        ButterKnife.bind(this);
        perfext_per_infoImp.attachView(this);
    }

    @OnClick({R.id.img_back, R.id.txt_back, R.id.finish_text})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.img_back:
                startActivity(new Intent(Perfect_Per_infoActivity.this, Perfect_Per_info_aActivity.class));
                finish();
                break;
            case R.id.txt_back:
                finish();
                break;
            case R.id.finish_text:
                perfext_per_infoImp.modinfo();
                break;
        }
    }

    @Override
    public void modSuccess(String msg) {
        String schoolName = ediSchool.getText().toString().trim();
        String studentName = ediName.getText().toString().trim();
        String studentSex = ediSex.getText().toString().trim();
        SharedPreferences.Editor editor = getSharedPreferences("data", MODE_PRIVATE).edit();
        editor.putString("schoolName", schoolName);
        editor.putString("studentName", studentName);
        editor.putString("studentSex", studentSex);
        editor.apply();
        new SweetAlertDialog(this, SweetAlertDialog.SUCCESS_TYPE)
                .setTitleText(msg)
                .setContentText("修改成功")
                .setConfirmClickListener(new SweetAlertDialog.OnSweetClickListener() {
                    @Override
                    public void onClick(SweetAlertDialog sweetAlertDialog) {
                        startActivity(new Intent(Perfect_Per_infoActivity.this, Perfect_Per_info_aActivity.class));
                        finish();
                    }
                })
                .show();
    }

    @Override
    public void modFail(String msg) {
        new SweetAlertDialog(this, SweetAlertDialog.ERROR_TYPE)
                .setTitleText(msg)
                .setContentText("请重新输入")
                .show();
    }

    @Override
    public void showToast(String msg) {

    }
}
